*** Settings ***
Library           FN

*** Test Cases ***
3.1 用户只存在一个未生效的后付费授权，通过接口查询用户授权状态，返回即将生效ONTINFORCE
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.oec.facade.info.EmpowerInfoFacade
    ${method}    Set Variable    queryEmpowerStatus
    ${customerId}    Get UUID
    ${serviceCode}    Set Variable    ${PTS_INFO['serviceCode']}
    ${serviceType}    Set Variable    ${PTS_INFO['serviceType']}
    ${charge_mode}    Set Int Variable    2    # 1预付费，2后付费
    ${power_sql}    Create Oec Power    not-power    ${customerId}    ${charge_mode}    1
    ${redis_key}    Get Oec Power Status Key    ${customerId}    ${serviceCode}    ${serviceType}
    Redis Step
    Connect To Redis    ${OEC_REDIS_URL}    ${OEC_REDIS_ALIAS}
    Delete Key From Redis    ${OEC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    Connect To Database    pymysql    ${OEC_DB_URL}    ${OEC_DB_ALIAS}
    Execute Sql String    ${OEC_DB_ALIAS}    DELETE from oec_consumable_empower_info where customer_id = '${customer_id}'    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OEC_DB_ALIAS}    ${power_sql}    ${DB_OP_TYPE_INSERT}
    Doing Step
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceCode    ${serviceCode}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    ${resp}    Dubbo Invoke    ${OEC_ZK_ADDR}    ${interface}    ${method}    ${post_data}
    Check Step
    Redis Key Should Be Exist    ${OEC_REDIS_ALIAS}    ${redis_key}    30
    ${redis_key_value}    Get Redis Key Value    ${OEC_REDIS_ALIAS}    ${redis_key}
    Equal As String    ${redis_key_value['empowerStatus']}    ${OEC_POWER_ONTINFORCE}
    Equal As String    ${resp['entity']['empowerStatus']}    ${OEC_POWER_ONTINFORCE}
    Validate Schema    ${resp}
    Close Step

3.2 用户只存在一个生效中的后付费授权，通过接口查询用户授权状态，返回生效中INFORCE
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.oec.facade.info.EmpowerInfoFacade
    ${method}    Set Variable    queryEmpowerStatus
    ${customerId}    Get UUID
    ${serviceCode}    Set Variable    ${PTS_INFO['serviceCode']}
    ${serviceType}    Set Variable    ${PTS_INFO['serviceType']}
    ${charge_mode}    Set Int Variable    2    # 1预付费，2后付费
    ${power_sql}    Create Oec Power    powering    ${customerId}    ${charge_mode}    1
    ${redis_key}    Get Oec Power Status Key    ${customerId}    ${serviceCode}    ${serviceType}
    Redis Step
    Connect To Redis    ${OEC_REDIS_URL}    ${OEC_REDIS_ALIAS}
    Delete Key From Redis    ${OEC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    Connect To Database    pymysql    ${OEC_DB_URL}    ${OEC_DB_ALIAS}
    Execute Sql String    ${OEC_DB_ALIAS}    DELETE from oec_consumable_empower_info where customer_id = '${customer_id}'    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OEC_DB_ALIAS}    ${power_sql}    ${DB_OP_TYPE_INSERT}
    Doing Step
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceCode    ${serviceCode}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    ${resp}    Dubbo Invoke    ${OEC_ZK_ADDR}    ${interface}    ${method}    ${post_data}
    Check Step
    Redis Key Should Be Exist    ${OEC_REDIS_ALIAS}    ${redis_key}    30
    ${redis_key_value}    Get Redis Key Value    ${OEC_REDIS_ALIAS}    ${redis_key}
    Equal As String    ${redis_key_value['empowerStatus']}    ${OEC_POWER_INFORCE}
    Equal As String    ${resp['entity']['empowerStatus']}    ${OEC_POWER_INFORCE}
    Validate Schema    ${resp}
    Close Step

3.3 用户只存在一个已失效的后付费授权，通过接口查询用户授权状态，返回已失效EXPIRED
    Init Step
    ${interface}    Set Variable    cn.com.servyou.business.oec.facade.info.EmpowerInfoFacade
    ${method}    Set Variable    queryEmpowerStatus
    ${customerId}    Get UUID
    ${serviceCode}    Set Variable    ${PTS_INFO['serviceCode']}
    ${serviceType}    Set Variable    ${PTS_INFO['serviceType']}
    ${charge_mode}    Set Int Variable    2    # 1预付费，2后付费
    ${power_sql}    Create Oec Power    powered    ${customerId}    ${charge_mode}    1
    ${redis_key}    Get Oec Power Status Key    ${customerId}    ${serviceCode}    ${serviceType}
    Redis Step
    Connect To Redis    ${OEC_REDIS_URL}    ${OEC_REDIS_ALIAS}
    Delete Key From Redis    ${OEC_REDIS_ALIAS}    ${redis_key}
    Mysql Step
    Connect To Database    pymysql    ${OEC_DB_URL}    ${OEC_DB_ALIAS}
    Execute Sql String    ${OEC_DB_ALIAS}    DELETE from oec_consumable_empower_info where customer_id = '${customer_id}'    ${DB_OP_TYPE_DELETE}
    Execute Sql String    ${OEC_DB_ALIAS}    ${power_sql}    ${DB_OP_TYPE_INSERT}
    Doing Step
    ${post_data}    Create Dictionary
    Set To Dictionary    ${post_data}    customerId    ${customerId}
    Set To Dictionary    ${post_data}    serviceCode    ${serviceCode}
    Set To Dictionary    ${post_data}    serviceType    ${serviceType}
    ${resp}    Dubbo Invoke    ${OEC_ZK_ADDR}    ${interface}    ${method}    ${post_data}
    Check Step
    Redis Key Should Be Exist    ${OEC_REDIS_ALIAS}    ${redis_key}    30
    ${redis_key_value}    Get Redis Key Value    ${OEC_REDIS_ALIAS}    ${redis_key}
    Equal As String    ${redis_key_value['empowerStatus']}    ${OEC_POWER_EXPIRED}
    Equal As String    ${resp['entity']['empowerStatus']}    ${OEC_POWER_EXPIRED}
    Validate Schema    ${resp}
    Close Step
